﻿; (function (window, undefined, $) {
    var submiting = false;
    $('#frmEdit').validator({
        rules: {

        },
        fields: {
            '#EnterpriseName': 'required',
            '#BorrowAmount': 'required',
            '#Tel': 'required',
            '#LoanPeriod': 'required'
        },
        valid: function (form) {
            if (submiting) {
                return;
            }
            submiting = true;
            FormSubmit(form, function(res) {
                if (res.Status > 0) {
                    alert(res.Message);
                    window.location.href = "/Admin/Enterprise/Enterprise";
                } else {
                    alert(res.Message);
                }
                submiting = false;
            });
        }
    });


    $("#btnSave").click(function (e) {
        //$("#Remarks").val($("#Rem").val());
        $("#frmEdit").submit();
    });
    $("#btnReturn").click(function (e) {
        window.location.href = "/Admin/Enterprise/Enterprise";
    });

    util.GetRates = function(id, num) {
        num = num.replace(/[^0-9|\.]/g, '');
        if (num > 1) {
            num = 1;
        }
        $('#' + id).val(num);
    };

    util.GetNum = function(id, num) {
        num = num.replace(/[^0-9|\.]/g, '');
        $('#' + id).val(num);
    };

    util.getFloatStr = function (id, num) {
        num = num.replace(/[^0-9|\.]/g, ''); //清除字符串中的非数字非.字符
        var no = changeTwoDecimal(parseFloat(num));
        if (!no) {
            $('#' + id).val('');
        }
        else {
            $('#' + id).val(no.toFixed(2));
        }
    };

    function changeTwoDecimal(x) {
        if (isNaN(x)) {
            return false;
        }
        f_x = Math.round(x * 100) / 100;
        return f_x;
    }


})(window, undefined, jQuery);